#include "graph.h"
#include<bits/stdc++.h>
#define For(i,j,k) for(int i=(j);i<=(k);i++)
#define ForD(i,j,k) for(int i=(j);i>=(k);i--)
using namespace std;
const int N=205,inf=1e9;
int pw[5];
int deg[N],fa[N],dep[N];
vector<int> S[N];
vector<int> Anc[N];
#define pb push_back
int n=1;
int Fa[N],Mp[N][N],Dep[N][N],Dis[N][N],Ans[N];
void dfs(int u){
    if(u!=1) fa[u]=LastRoad(),dep[u]=dep[Fa[u]]+1;
    else dep[u]=0;
    deg[u]=NumberOfRoads();
    For(i,1,deg[u]) if(i!=fa[u]){
        Move(i,2);
        int col=Color();
        if(col==1){
            n++;
            S[u].pb(i);
            Fa[n]=u;
            Mp[u][i]=n;
            dfs(n);
        }else if(col==2){
            Anc[u].pb(i);
            assert(i!=fa[u]);
            Move(LastRoad(),2);
        }else if(col==3) Move(LastRoad(),3);
        else assert(0);
    }
    if(u!=1) Move(fa[u],3);
}
void dfs2(int u,int b){
    int col=(dep[u]/pw[b])%3+1;
    for(int i:Anc[u]){
        Move(i,col);
        int tmp=Color();
        Dep[u][i]+=(pw[b]*(tmp-1));
        Move(LastRoad(),tmp);
    }
    for(int i:S[u]){
        int v=Mp[u][i];
        Move(i,col);
        dfs2(v,b);
    }
    if(u!=1) Move(fa[u],1);
}
void Inspect(int R) {
    // Write your code here.
    pw[0]=1;
    For(i,1,4) pw[i]=pw[i-1]*3;
    dfs(1);
    For(i,0,4) dfs2(1,i);
    For(i,1,n) For(j,1,n) Dis[i][j]=inf;
    For(i,1,n) Dis[i][i]=0;
    For(u,2,n) Dis[u][Fa[u]]=Dis[Fa[u]][u]=1;
    For(u,2,n) for(int i:Anc[u]){
        int d=Dep[u][i];
        assert(d<dep[u]);
        int nw=u,tmp=dep[u];
        while(tmp>d){
            nw=Fa[nw];
            tmp--;
        }
        assert(nw);
        Dis[nw][u]=Dis[u][nw]=1;
    }
    For(k,1,n) For(i,1,n) For(j,1,n) if(Dis[i][k]+Dis[k][j]<Dis[i][j]) Dis[i][j]=Dis[i][k]+Dis[k][j];
    For(i,1,n) For(j,1,i-1) Ans[Dis[i][j]]++;
    For(i,1,R) Answer(i,Ans[i]);
}
